﻿using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace WinUITest.Pages
{
    [Menu("Lottie动画", "\uE786")]
    public sealed partial class AnimatedVisualPlayerPage : Page
    {
        public AnimatedVisualPlayerPage() => InitializeComponent();
        private void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            Player.PlaybackRate = 1;
            EnsurePlaying();
        }
        private void PauseButton_Checked(object sender, RoutedEventArgs e) => Player.Pause();
        private void PauseButton_Unchecked(object sender, RoutedEventArgs e) => Player.Resume();
        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            Player.Stop();
            PauseButton.IsChecked = false;
        }
        private void ReverseButton_Click(object sender, RoutedEventArgs e)
        {
            Player.PlaybackRate = -1;
            EnsurePlaying();
        }
        private void EnsurePlaying()
        {
            if (PauseButton.IsChecked is null) return;
            if (PauseButton.IsChecked.Value)
            {
                PauseButton.IsChecked = false;
            }
            else if (!Player.IsPlaying)
            {
                _ = Player.PlayAsync(fromProgress: 0, toProgress: 1, looped: false);
            }
        }
    }
}
